Skip to content

perf(shader): cache BDA ranges in span reads - #270

Draft
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/14260
Draft

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/14260

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#14260, originally opened by kiansaeidnia.

Source commit: 8630fa906d675132ad2741f997c275edb36434f9. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Draft: not ready for review yet. The change and the results below are real; the open items are listed at the end of this section.

Address-based (BDA) span reads walk the BDA table (probe_bda_pointer) on every access. A program that runs as one wave pays every walk on its critical path, because nothing else is resident to hide the latency. In Ghost of Yotei's opening cinematic, the single-wave program 0x807b90a100 spends 94 % of its time in a triangle loop of six runtime-format buffer loads. Shader-clock instrumentation of that loop shows the table walk is about a third of each load (~2,950 of ~8,400 cycles); the data load itself is ~220 cycles.

Each invocation now keeps the last four ranges its span reads found, as (begin, bound, device base) entries.

  • A read inside one of them translates directly.
  • A miss walks the table with the existing range-returning lookup (bda_anchor_range, with the same checks as the probe) and replaces the oldest entry with the range it finds.
  • A kept range ends at the next range's start, which is the first address the walk would resolve elsewhere, so a hit resolves exactly as the walk would.
  • An unmapped span still returns 0 and takes the same fault path as before.

The entries are separate variables indexed only by constants. A first version indexed 16 slots by pc; its dynamically indexed array added 512 bytes of local memory per thread on NVIDIA, and that showed up as 270 MB more VRAM in the frame replay. The four-entry version adds 176 bytes and about 40 MB.

APS5_NO_BDA_RANGE_CACHE=1 walks the table for every read, as before.

Still to do before this is ready:

  • A main-vs-PR summary from the same machine and scene. Ghost of Yotei only runs on the Celegans12 yotei/best fork, so the in-game numbers below come from that fork, not from main. I still need a title or homebrew that runs on main and exercises address-based span reads.
  • The replay and in-game tables were measured on the first (pc-indexed) version, or alongside a separate ballot change. They need repeating with exactly this commit.
  • fix(shader): mask writes after barrier-safe BDA faults boykopovar/AnyPS5#7392 edits the same span-read function (BdaSpanReadResultType and the stop handling) for a different purpose, masking writes after faults. Whichever lands second needs a rebase.

Overlap: the pr-overlap bot could not compare 54 open PRs that conflict with main, so I reviewed them by hand.

Tested

Windows 11 Pro 10.0.26200, RTX 3080 Ti, NVIDIA 616.92.

  • New agc_driver_bda_range_cache test. Eight loads over five guest blocks: A, A again (a hit), then B, C and D (misses), E (evicts A), A (evicts B) and B. It runs on wave32, wave64 and split wave64, with and without glc, and also passes with APS5_NO_BDA_RANGE_CACHE=1.

  • Focused tests on this branch rebased onto main 6fe120d, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (ctest -R "bda_range_cache|bda_span_reads|bda_anchor_reads|bda_device|global_loads|gpu_buffer_format|buffer_format|descriptor_web_faults|buffer_load_store" -V):

    • main: 15/15 passed.
    • This PR: 16/16 passed (the same 15 plus the new test).
    • Neither log has a VUID- line or a missing-layer message.
  • spirv-val --target-env vulkan1.3 passes for the five largest captured Ghost of Yotei programs (on the earlier base).

  • Frame replay (agc_frame_replay, exact mode) of a captured cinematic frame, alternating runs with the cache off and on. These runs used the first, pc-indexed version; the four-entry version gives 0x807b90a100 122.5 ms in the same replay. Output buffers are byte-identical in every run.

    Cache off Cache on
    0x807b90a100 174.7, 172.1 ms 120.7, 120.8 ms (−30 %)
    0x801edd2700 162, 176 ms 114, 120 ms (−30 %)
    All timed GPU work 678, 629 ms 576, 591 ms

    Shader-clock cycles of 0x807b90a100 and 0x807b925400 drop 34 % with the first version. With four entries, 1 of 42,846 reads walks the table.

  • In game, Ghost of Yotei (PPSA26344), on the yotei/best fork's runtime (see above). The change build also carried a spanned-ballot change that measured −1 to −6 % on these programs. Warm shader cache, tools/trace_digest.py of aps5-summary.jsonl:

    Without With
    Logo screens, presents per 10 s (p50) 70 (143 ms) 78 (129 ms)
    Opening cinematic, presents per 10 s 3.2–4.4 (5 runs) 4.95
    GPU busy per present in the cinematic 1,251–1,685 ms 959 ms
    0x807b90a100 / 0x807b925400 / 0x801edd2700 per run 155 / 129 / 20 ms 87 / 73 / 11 ms

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 616.92, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

A span read walked the BDA table for every access. Single-wave
address-based programs pay that walk on their critical path: in Ghost of
Yotei's opening cinematic, 0x807b90a100 spends 94 % of its time in a
triangle loop of six runtime-format buffer loads, and the walk was about
a third of each load.

Each invocation now keeps the last four ranges its span reads found. A
read inside one of them translates directly; a miss walks the table with
the range-returning lookup and replaces the oldest entry with the range
it finds. A kept range ends at the next range's start, so a hit resolves
exactly as the walk would. The entries are separate variables indexed by
constants, which keeps their local-memory footprint small.

APS5_NO_BDA_RANGE_CACHE=1 walks the table for every read, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants